<%--
  @author Duminda Dharmakeerthi
  @author Supun Nimesh Karunathilaka
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dateSelector.js"></script>
<script src="${pageContext.request.contextPath}/js/landRegistration/shortTermLease.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        validateShortTermLeaseDetails();

    });

    function validateShortTermLeaseDetails() {
        $('#issueDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });

    }

    function initialValidate() {
        initialShortTermLease();
    }
    function detailValidate() {
        //      alert("detail");
    }
    function showViolationComment() {
        $('#violationComment').show();
    }

    function hideViolationComment() {
        $('#violationComment').hide();
        $('#conditionsViolationComment').val('');
    }

    function violationCommentClick() {
        if ($('#conditionsViolatedOrNot0').is(':checked')) {
            hideViolationComment();
        } else {
            showViolationComment();
        }
    }
</script>
<script type="text/javascript">
    function disableFields() {
        var fields = new Array(
                'referenceNo',
                'issueDate',
            //'folioNo',
            //'folioDate',
            //'folioLocation',
                'developmentState',
                'conditionsViolatedOrNot0',
                'conditionsViolatedOrNot1',
                'conditionsViolationComment',
                'valuation',
                'rental',
                'permittedLandUsageId',
                'currentLandUsageId'
                );
        enableFields(fields);
    }

    $(function () {
        $('#nominatedSuccessor').hide();
        if ($('#approvalState').val() == 'PENDING' && (  (  ($('#userRole').val() == 'ORDS') ) || (  ($('#editMode').val() != 1)  &&   ($('#userRole').val() == 'ORIP')   ) ) ) {
            disableFields();
        }
        if ($('#landMode').val() == 'DETAIL') {
            violationCommentClick();
        } else {
            hideViolationComment();
        }
    });

    $(function() {
        $('#valuation').change(function() {
            $('#rental').val(($('#valuation').val() * 0.04));
        });
    });
</script>

<div id="tabs">
    <ul>
        <li><s:a href="#annual-lease-details"><s:label
                value="%{getText('short_term_lease_details.label')}"/></s:a></li>
        <li><s:a href="#personal-details"><s:label value="%{getText('holder_details.label')}"/></s:a></li>
        <li><s:a href="#occupier-details"><s:label value="%{getText('occupier_details.label')}"/></s:a></li>
    </ul>
    <div id="annual-lease-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('lease_no.label')}"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="referenceNo" name="alienation.referenceNo" cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('issue_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                               cssClass="date-format"/></td>
                <td><s:textfield id="issueDate" name="alienation.issueDate" onclick="selectDate('issueDate')"
                                 cssClass="width-200-px" onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <%-- <tr>
              <td><s:label value="%{getText('folio_no.label')}"/></td>
              <td><s:textfield id="folioNo" name="alienation.folioNumber" cssClass="width-200-px"/></td>
              <td><s:label value="%{getText('folio_date.label')}"/> <s:label value="%{getText('date_format.label')}" cssClass="date-format"/></td>
              <td><s:textfield id="folioDate" name="alienation.folioDate" onclick="selectDate('folioDate')"
                               cssClass="width-200-px"/></td>
          </tr>
          <tr>
              <td><s:label value="%{getText('folio_location.label')}"/></td>
              <td colspan="3"><s:textarea id="folioLocation" name="alienation.folioLocation" rows="1"
                                          cssClass="width-595-px"/></td>
          </tr>  --%>
            <tr>
                <td><s:label value="%{getText('valuation.label')}"/> <s:label value="%{getText('rs.label')}"/></td>
                <td><s:textfield id="valuation" name="alienation.valuation" cssClass="width-200-px"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="%{getText('rental.label')}"/> <s:label value="%{getText('rs.label')}"/></td>
                <td><s:textfield id="rental" name="alienation.rental" cssClass="width-200-px"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('purpose_of_lease.label')}"/></td>
                <td colspan="3"><s:select id="permittedLandUsageId" name="alienation.permittedUsage.id"
                                          list="landUsageList" cssClass="width-200-px"
                                          headerKey="0" headerValue="%{getText('select.label')}"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('present_usage.label')}"/></td>
                <td colspan="3"><s:select id="currentLandUsageId" name="alienation.currentLandUsage.id"
                                          list="landUsageList" headerKey="0" cssClass="width-200-px"
                                          headerValue="%{getText('select.label')}"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('developed_status.label')}"/></td>
                <td colspan="3" class="left-align"><s:textarea id="developmentState" rows="1"
                                                               name="alienation.developmentState"
                                                               cssClass="width-595-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('conditionsViolatedOrNot.label')}"/></td>
                <td colspan="2"><s:radio id="conditionsViolatedOrNot" name="alienation.conditionsViolatedOrNot"
                                         list="#@java.util.HashMap@{'1':getText('yes.label'),'0':getText('no.label')}"
                                         onclick="violationCommentClick()"/></td>
            </tr>
            <tr id="violationComment">
                <td><s:label value="%{getText('conditionsViolationComment.label')}"/></td>
                <td colspan="3"><s:textarea id="conditionsViolationComment" name="alienation.conditionsViolationComment"
                                            rows="1"
                                            cssClass="width-595-px"/></td>
            </tr>
        </table>
    </div>

    <div id="personal-details">
        <table class="width-100">
            <s:include value="../personalDetails.jsp"/>
        </table>
    </div>
    <div id="occupier-details">
        <table class="width-100">
            <s:include value="../encroacherDetails.jsp"/>
        </table>
    </div>
</div>

<s:hidden name="alienation.id"/>
<s:hidden name="alienation.holder.id"/>
<s:hidden name="alienation.holder.contacts.id"/>
<s:hidden name="alienation.holder.holderType" value="1"/>


<s:hidden id="pls_enter_reference_no" value="%{getText('pls_enter_reference_no')}"/>
<s:hidden id="pls_enter_name_of_the_land" value="%{getText('pls_enter_name_of_the_land')}"/>
<s:hidden id="pls_enter_plan_no" value="%{getText('pls_enter_plan_no')}"/>
<s:hidden id="pls_enter_lot_no" value="%{getText('pls_enter_lot_no')}"/>
<s:hidden id="pls_enter_valid_no" value="%{getText('pls_enter_valid_no')}"/>
<s:hidden id="pls_select_gn_division" value="%{getText('pls_select_gn_division')}"/>